home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / mail / pine3.96.tar.gz / pine3.96.tar / pine3.96 / pine / osdep / fnexpand < prev    next >
Text File  |  1993-08-11  |  1KB  |  39 lines

  1. struct passwd *getpwnam();
  2.  
  3. /*----------------------------------------------------------------------
  4.        Expand the ~ in a file ala the csh (as home directory)
  5.  
  6.    Args: buf --  The filename to expand (nothing happens unless begins with ~)
  7.          len --  The length of the buffer passed in (expansion is in place)
  8.  
  9.  Result: Expanded string is returned using same storage as passed in.
  10.          If expansion fails, NULL is returned
  11.  ----*/
  12. char *
  13. fnexpand(buf, len)
  14.     char *buf;
  15.     int len;
  16. {
  17.     struct passwd *pw;
  18.     register char *x,*y;
  19.     char name[20];
  20.     
  21.     if(*buf == '~') {
  22.         for(x = buf+1, y = name; *x != '/' && *x != '\0'; *y++ = *x++);
  23.         *y = '\0';
  24.         if(x == buf + 1) 
  25.           pw = getpwuid(getuid());
  26.         else
  27.           pw = getpwnam(name);
  28.         if(pw == NULL)
  29.           return((char *)NULL);
  30.         if(strlen(pw->pw_dir) + strlen(buf) > len) {
  31.           return((char *)NULL);
  32.         }
  33.         rplstr(buf, x - buf, pw->pw_dir);
  34.     }
  35.     return(len ? buf : (char *)NULL);
  36. }
  37.  
  38.  
  39.